package cc.atliberty.oa.controller;

import cc.atliberty.oa.pojo.Dept;
import cc.atliberty.oa.service.DeptService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/dept/list")
public class ListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 查询dept表，将dept封装成对象给jsp页面
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        DeptService deptService = context.getBean("deptService", DeptService.class);
        List<Dept> depts = deptService.deptDetail();
        request.setAttribute("deptList", depts);
        request.getRequestDispatcher("/list.jsp").forward(request,response);
    }
}
